Imports IBANFuncs.Core

Public Class frmMain
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents cboCountries As System.Windows.Forms.ComboBox
    Friend WithEvents txtBankCode As System.Windows.Forms.TextBox
    Friend WithEvents txtBranchCode As System.Windows.Forms.TextBox
    Friend WithEvents txtAccountNumber As System.Windows.Forms.TextBox
    Friend WithEvents cmdSynthesize As System.Windows.Forms.Button
    Friend WithEvents lblComments As System.Windows.Forms.Label
    Friend WithEvents lblIBAN As System.Windows.Forms.Label
    Friend WithEvents ctxLabel As System.Windows.Forms.ContextMenu
    Friend WithEvents mnuCopyToClipboard As System.Windows.Forms.MenuItem
    Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents txtIBAN As System.Windows.Forms.TextBox
    Friend WithEvents cmdAnalyzeIBAN As System.Windows.Forms.Button
    Friend WithEvents lblIBANContents As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.GroupBox1 = New System.Windows.Forms.GroupBox
        Me.lblIBAN = New System.Windows.Forms.Label
        Me.lblComments = New System.Windows.Forms.Label
        Me.cmdSynthesize = New System.Windows.Forms.Button
        Me.txtAccountNumber = New System.Windows.Forms.TextBox
        Me.txtBranchCode = New System.Windows.Forms.TextBox
        Me.txtBankCode = New System.Windows.Forms.TextBox
        Me.cboCountries = New System.Windows.Forms.ComboBox
        Me.Label4 = New System.Windows.Forms.Label
        Me.Label3 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label1 = New System.Windows.Forms.Label
        Me.ctxLabel = New System.Windows.Forms.ContextMenu
        Me.mnuCopyToClipboard = New System.Windows.Forms.MenuItem
        Me.GroupBox2 = New System.Windows.Forms.GroupBox
        Me.lblIBANContents = New System.Windows.Forms.Label
        Me.cmdAnalyzeIBAN = New System.Windows.Forms.Button
        Me.txtIBAN = New System.Windows.Forms.TextBox
        Me.Label5 = New System.Windows.Forms.Label
        Me.GroupBox1.SuspendLayout()
        Me.GroupBox2.SuspendLayout()
        Me.SuspendLayout()
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.Add(Me.lblIBAN)
        Me.GroupBox1.Controls.Add(Me.lblComments)
        Me.GroupBox1.Controls.Add(Me.cmdSynthesize)
        Me.GroupBox1.Controls.Add(Me.txtAccountNumber)
        Me.GroupBox1.Controls.Add(Me.txtBranchCode)
        Me.GroupBox1.Controls.Add(Me.txtBankCode)
        Me.GroupBox1.Controls.Add(Me.cboCountries)
        Me.GroupBox1.Controls.Add(Me.Label4)
        Me.GroupBox1.Controls.Add(Me.Label3)
        Me.GroupBox1.Controls.Add(Me.Label2)
        Me.GroupBox1.Controls.Add(Me.Label1)
        Me.GroupBox1.Location = New System.Drawing.Point(8, 8)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(352, 272)
        Me.GroupBox1.TabIndex = 0
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "IBAN Synthesis"
        '
        'lblIBAN
        '
        Me.lblIBAN.Location = New System.Drawing.Point(28, 236)
        Me.lblIBAN.Name = "lblIBAN"
        Me.lblIBAN.Size = New System.Drawing.Size(296, 23)
        Me.lblIBAN.TabIndex = 10
        Me.lblIBAN.Text = "No IBAN calculated"
        Me.lblIBAN.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'lblComments
        '
        Me.lblComments.Location = New System.Drawing.Point(8, 152)
        Me.lblComments.Name = "lblComments"
        Me.lblComments.Size = New System.Drawing.Size(336, 40)
        Me.lblComments.TabIndex = 9
        Me.lblComments.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'cmdSynthesize
        '
        Me.cmdSynthesize.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(161, Byte))
        Me.cmdSynthesize.Location = New System.Drawing.Point(132, 200)
        Me.cmdSynthesize.Name = "cmdSynthesize"
        Me.cmdSynthesize.Size = New System.Drawing.Size(89, 23)
        Me.cmdSynthesize.TabIndex = 8
        Me.cmdSynthesize.Text = "Create IBAN"
        '
        'txtAccountNumber
        '
        Me.txtAccountNumber.Location = New System.Drawing.Point(95, 120)
        Me.txtAccountNumber.Name = "txtAccountNumber"
        Me.txtAccountNumber.Size = New System.Drawing.Size(248, 21)
        Me.txtAccountNumber.TabIndex = 7
        Me.txtAccountNumber.Text = ""
        '
        'txtBranchCode
        '
        Me.txtBranchCode.Location = New System.Drawing.Point(95, 88)
        Me.txtBranchCode.Name = "txtBranchCode"
        Me.txtBranchCode.Size = New System.Drawing.Size(248, 21)
        Me.txtBranchCode.TabIndex = 6
        Me.txtBranchCode.Text = ""
        '
        'txtBankCode
        '
        Me.txtBankCode.Location = New System.Drawing.Point(95, 56)
        Me.txtBankCode.Name = "txtBankCode"
        Me.txtBankCode.Size = New System.Drawing.Size(248, 21)
        Me.txtBankCode.TabIndex = 5
        Me.txtBankCode.Text = ""
        '
        'cboCountries
        '
        Me.cboCountries.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cboCountries.Location = New System.Drawing.Point(95, 24)
        Me.cboCountries.Name = "cboCountries"
        Me.cboCountries.Size = New System.Drawing.Size(248, 21)
        Me.cboCountries.TabIndex = 4
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(8, 120)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(80, 23)
        Me.Label4.TabIndex = 3
        Me.Label4.Text = "Account #:"
        Me.Label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(8, 88)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(80, 23)
        Me.Label3.TabIndex = 2
        Me.Label3.Text = "Branch code:"
        Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(8, 56)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(80, 23)
        Me.Label2.TabIndex = 1
        Me.Label2.Text = "Bank code:"
        Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(8, 24)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(80, 23)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "Country:"
        Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'ctxLabel
        '
        Me.ctxLabel.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuCopyToClipboard})
        '
        'mnuCopyToClipboard
        '
        Me.mnuCopyToClipboard.Index = 0
        Me.mnuCopyToClipboard.Text = "Copy to clipboard"
        '
        'GroupBox2
        '
        Me.GroupBox2.Controls.Add(Me.lblIBANContents)
        Me.GroupBox2.Controls.Add(Me.cmdAnalyzeIBAN)
        Me.GroupBox2.Controls.Add(Me.txtIBAN)
        Me.GroupBox2.Controls.Add(Me.Label5)
        Me.GroupBox2.Location = New System.Drawing.Point(368, 8)
        Me.GroupBox2.Name = "GroupBox2"
        Me.GroupBox2.Size = New System.Drawing.Size(312, 272)
        Me.GroupBox2.TabIndex = 1
        Me.GroupBox2.TabStop = False
        Me.GroupBox2.Text = "IBAN Analysis"
        '
        'lblIBANContents
        '
        Me.lblIBANContents.Location = New System.Drawing.Point(8, 88)
        Me.lblIBANContents.Name = "lblIBANContents"
        Me.lblIBANContents.Size = New System.Drawing.Size(296, 176)
        Me.lblIBANContents.TabIndex = 10
        Me.lblIBANContents.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'cmdAnalyzeIBAN
        '
        Me.cmdAnalyzeIBAN.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(161, Byte))
        Me.cmdAnalyzeIBAN.Location = New System.Drawing.Point(112, 56)
        Me.cmdAnalyzeIBAN.Name = "cmdAnalyzeIBAN"
        Me.cmdAnalyzeIBAN.Size = New System.Drawing.Size(89, 23)
        Me.cmdAnalyzeIBAN.TabIndex = 9
        Me.cmdAnalyzeIBAN.Text = "Create IBAN"
        '
        'txtIBAN
        '
        Me.txtIBAN.Location = New System.Drawing.Point(56, 24)
        Me.txtIBAN.Name = "txtIBAN"
        Me.txtIBAN.Size = New System.Drawing.Size(248, 21)
        Me.txtIBAN.TabIndex = 6
        Me.txtIBAN.Text = ""
        '
        'Label5
        '
        Me.Label5.Location = New System.Drawing.Point(8, 24)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(48, 23)
        Me.Label5.TabIndex = 1
        Me.Label5.Text = "IBAN:"
        Me.Label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'frmMain
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 14)
        Me.ClientSize = New System.Drawing.Size(688, 309)
        Me.Controls.Add(Me.GroupBox2)
        Me.Controls.Add(Me.GroupBox1)
        Me.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(161, Byte))
        Me.MaximizeBox = False
        Me.Name = "frmMain"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "IBANFuncs - Win Form"
        Me.GroupBox1.ResumeLayout(False)
        Me.GroupBox2.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Try
            IBANDefinitions.ReadDefinitions("..\..\IBANFuncsCore\IBANDefinitions.xml")
        Catch ex As Exception
            MessageBox.Show("Exception: " + ex.ToString, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try

        For i As Integer = 0 To IBANDefinitions.GetNumberCountries - 1
            Dim countryDef As IBANCountryDef = IBANDefinitions.GetCountry(i)
            cboCountries.Items.Add(countryDef.CountryCode + " - " + countryDef.CountryName)
        Next

        cboCountries.SelectedIndex = 0

    End Sub

    Private Sub cboCountries_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboCountries.SelectedIndexChanged

        If cboCountries.SelectedIndex = -1 Then
            lblComments.Text = ""
        Else
            lblComments.Text = IBANDefinitions.FindCountryByCode(cboCountries.SelectedItem.Substring(0, 2)).Comments
        End If

    End Sub

    Private Sub cmdAnalyzeIBAN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAnalyzeIBAN.Click
        Try
            Dim IBAN As IBANContents = IBANAnalyzer.AnalyzeIBAN(txtIBAN.Text)
            lblIBANContents.Text = "Country: " + IBAN.CountryCode + vbCrLf + _
                                   "Check digits: " + IBAN.CheckDigits + vbCrLf + _
                                   "Bank code: " + IBAN.BankCode + vbCrLf + _
                                   "Branch code: " + IBAN.BranchCode + vbCrLf + _
                                   "Account number: " + IBAN.AccountNumber
        Catch ex As Exception
            lblIBANContents.Text = ex.ToString()
        End Try
    End Sub

    Private Sub cmdSynthesize_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSynthesize.Click
        Try
            Dim IBANStr As String = IBANCreator.CreateIBAN(New IBANContents(cboCountries.Text.Substring(0, 2), _
                                                    "", txtBankCode.Text, _
                                                    txtBranchCode.Text, _
                                                    txtAccountNumber.Text), True)
            lblIBAN.Text = IBANStr
        Catch ex As Exception
            lblIBAN.Text = ex.Message()
        End Try
    End Sub
End Class
